﻿using SuperX.Common.Helper;
using SuperX.Common.Log;
using System;
using System.Collections.Generic;
using System.Text;

namespace SuperX.Helper.OS.LinuxCmds
{
    [Command("^Red Hat Enterprise Linux", "^CentOS Linux release")]
    public class CentOSCommand : LinuxCommand
    {
        public override string PackageSuffix => "rpm";

        protected override List<string> GenerateReInstallScript(string fullName)
        {
            var list = new List<string>
            {
                "rpm -e IoTRun",
                "rpm -i \"" + fullName + "\""
            };
            return list;
        }

        public override void CheckOtherUpdate(InvokeMsg invokeMessage)
        {
            //暂时不知道在CentOS下会不会有影响
        }

        public override void GetNTP(NTPContext ntpContext)
        {
            try
            {
                var chronyManager = new ChronyManager();
                var context = chronyManager.ReadNTPContext();
                ntpContext.EnableNTPClient = context.EnableNTPClient;
                ntpContext.EnableNTPServer = context.EnableNTPServer;
                ntpContext.NTPServerIP = context.NTPServerIP;
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
            }
        }

        public override void SetNTP(NTPContext ntpContext)
        {
            try
            {
                var chronyManager = new ChronyManager();
                chronyManager.SetNTPContext(ntpContext);
            }
            catch (Exception ex)
            {
                Logger.Exception(ex);
            }
        }
    }
}